class Permutation{
	
	public static void permute(String str){
		int length = str.length();
		boolean[] used = new boolean[length];
		StringBuilder out = new StringBuilder();
		char[] in = str.toCharArray();
		
		doPermute(in, out, used, length, 0);
	}
	
	public static void doPermute(char[] in, StringBuilder out, boolean[] used, int length, int level){
		if(level == length){
			System.out.println(out.toString());
			return;
		}
		for (int i=0;i < length; i++){
			if(used[i]) continue;
			out.append(in[i]);
			System.out.println("append and set true="+in[i]+",out is "+out);
			used[i] = true;
			doPermute(in,out,used,length,level+1);
			System.out.println("set false="+in[i]+", and level is "+(level+1));			
			used[i]=false;
			System.out.println("Length="+out.length());
			out.setLength(out.length()-1); // because used[i]=false
		}
	}
	
	public static void main(String[] args){
		permute("abc");
	}
}